{extend name="base"}
{block name="title"}消息列表{/block}
{block name="head"}{/block}
{block name="body"}
<body class="mainbody">
<form>
<!--导航栏-->
<div class="location">
  <a href="javascript:history.back(-1);" class="back"><i class="iconfont icon-up"></i><span>返回上一页</span></a>
  <a href="{:url('index/home')}" class="home"><i class="iconfont icon-home"></i><span>首页</span></a>
  <i class="arrow iconfont icon-arrow-right"></i>
  <span>消息列表</span>
</div>
<!--/导航栏-->

<!--工具栏-->
<div id="floatHead" class="toolbar-wrap">
  <div class="toolbar">
    <div class="box-wrap">
      <a class="menu-btn"><i class="iconfont icon-more"></i></a>
      <div class="l-list">
        <div class="menu-list">
          <div class="rule-single-select">
            <select name="channel" style="display:none">
              <option value="-1">===所有渠道===</option>
              <option value="0" {eq name="channel" value="0"} selected{/eq}>[0]全部渠道</option>
              {volist name="CHANNELS" id="val"}
              <option value="{$key}"{eq name="channel" value="$key"} selected{/eq}>[{$key}]{$val.Name}</option>
              {/volist}
            </select>
          </div>
          <div class="rule-single-select">
            <select name="mt" style="display:none">
              <option value="0">===所有类型===</option>
              {volist name="MessageType" id="val"}
              <option value="{$key}"{eq name="mt" value="$key"} selected{/eq}>[{$key}]{$val}</option>
              {/volist}
            </select>
          </div>
          <div class="rule-single-select">
            <select name="ut" style="display:none">
              <option value="0">===发布范围===</option>
              {volist name="UserType" id="val"}
              <option value="{$key}"{eq name="ut" value="$key"} selected{/eq}>[{$key}]{$val}</option>
              {/volist}
            </select>
          </div>

          <div class="rule-single-select">
            <select name="IsPass" style="display:none">
              <option value="-1">===是否启用===</option>
              <option value="0"{eq name="IsPass" value="0"} selected{/eq}>[0]启用</option>
              <option value="1"{eq name="IsPass" value="1"} selected{/eq}>[1]禁用</option>
            </select>
          </div>
        </div>
      </div>
      <div class="r-list">
        <a class="input">发布新用户的消息</a>
      </div>
    </div>
  </div>
</div>
<!--/工具栏-->

<div class="table-container">
  <table border="0" cellspacing="0" cellpadding="0" class="border-table ltable">
    <thead>
      <tr>
        <th>#</th>
        <th>ID</th>
        <th>渠道</th>
        <th>开始时间</th>
        <th>消息类型</th>
        <th>消息标题</th>
        <th>消息内容</th>
        <th>发布范围</th>
        <th>是否启用</th>
        <th>修改时间</th>
        <th>操作</th>
      </tr>
    </thead>
    <tbody>
{empty name="list"}
      <tr><td colspan="9">Oh~暂无数据!</td></tr>
{else}
  {volist name="list" id="v"}
      <tr data-id="{$v.ID}">
        <td>{$v.ROW_NUMBER}</td>
        <td>{$v.ID}</td>
        <td>[{$v.Channel}]{neq name="$v.Channel" value="0"}{$CHANNELS[$v.Channel]['Name']}{else/}全部渠道{/neq}</td>
        <td>{$v.CreateDate}</td>
        <td style="color:{gt name='v.MsgType' value='1'}red{else}green{/gt}">[{$v.MsgType}]{switch name="v.MsgType"}{case value="1"}通知{/case}{case value="2"}补偿{/case}{/switch}</td>
        <td style="white-space:normal; word-break: break-all;">{:htmlentities($v.MsgTitle)}</td>
        <td style="white-space:normal; word-break: break-all;">{:htmlentities($v.MsgContent)}</td>
        <td>[{$v.UserType}]{switch name="v.UserType"}{case value="1"}所有用户{/case}{case value="2"}代理用户{/case}{case value="3"}玩家用户{/case}{case value="4"}指定用户{/case}{/switch}</td>
        <td style="color:{gt name='v.IsPass' value='0'}red{else}green{/gt}" title="{$v.IsPass}">{gt name='v.IsPass' value='0'}禁用{else}启用{/gt}</td>
        <td>{$v.UpdateTime}</td>
        <td>
          <a class="input">修改</a>
          <a class="input">删除</a>
        </td>
      </tr>
  {/volist}
{/empty}
    </tbody>
  </table>
</div>

<!--内容底部-->
<div class="page-footer"><div class="btn-wrap">{$list->render()}</div></div>
<!--/内容底部-->

</form>
<script>
$.extend({
  SystemMsg: { //邮件的相关操作
    ShowDetailDialog: function (id) {

      var url = "{:url('detail')}?id=" + id;
      dialog($.extend({
          title: '详情[' + id + ']',
          url: url,
          width: 700,
          height: 530,
          okValue: '确认提交',
          ok: function () {
            var f = $('iframe', this.node);
            var v = $('form', f.contents()).serialize();
            // console.log(f);
            // console.log(v);
            $.post(url, v, function (resp, state, xhr) {
              // console.log(resp);
              alert(resp.error);
              if (resp.errno == 0) {
                location.reload();
              }
            });
            return false;
          }
        }, id > 0 ? {
          button: [{
              value: '删除规则',
              autofocus: true,
              callback: function () {
                $.SystemMsg.ShowDeleteConfirm(id);
                return false;
              }
            }
          ]
        } : {})).showModal();
    },
    ShowDeleteConfirm: function (id) {
      dialog({
        title: '提示',
        content: '确定删除?id=' + id,
        width: 200,
        height: 30,
        okValue: '确认',
        ok: function () {
          var url = "{:url('delete')}?id=" + id;
          $.post(url, function (resp, state, xhr) {
            // console.log(resp);
            alert(resp.error);
            if (resp.errno == 0) {
              location.reload();
            }
          });
          return false;
        }
      }).showModal();
    }
  }
});

$(function () {
  $('.toolbar a.input').click(function () { // 新建
    $.SystemMsg.ShowDetailDialog(0);
  });
  $('table.ltable td:last-child a.input:nth-child(1)').click(function () {  // 修改
    var id = $(this).parents('tr').attr('data-id');
    $.SystemMsg.ShowDetailDialog(id);
  });
  $('table.ltable td:last-child a.input:nth-child(2)').click(function () {  // 删除
    var id = $(this).parents('tr').attr('data-id');
    $.SystemMsg.ShowDeleteConfirm(id);
  });

});
</script>
</body>
{/block}